﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

using System.Configuration;


namespace StockMentor
{
   public class CustomProcedures
    {
        public static SqlConnection conn;

        public static int UPDATEFIRMA(
            System.DateTime dActualizare, 
            System.String sDenumire,
            System.String sCif, 
            System.String sRegCom, 
            System.String sRecepSerie,
            System.Int32 iRecepNr,
            System.String sFactSerie,
            System.Int32 iFactNr,
            System.String sTel,
            System.String sFax,
            System.String sEmail,
            System.String sWeb,
            System.String sAdresa,
            System.Double dCS,
            object chTva)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[17];
            parameters[0] = new SqlParameter("@parData", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dActualizare);
            parameters[1] = new SqlParameter("@parDenumire", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sDenumire);
            parameters[2] = new SqlParameter("@parCif", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sCif);
            parameters[3] = new SqlParameter("@parRegCom", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sRegCom);
            parameters[4] = new SqlParameter("@parRecepSerie", SqlDbType.VarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sRecepSerie);
            parameters[5] = new SqlParameter("@parRecepNr", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iRecepNr);
            parameters[6] = new SqlParameter("@parRecepNr", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iRecepNr);
            parameters[7] = new SqlParameter("@parFactSerie", SqlDbType.VarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactSerie);
            parameters[8] = new SqlParameter("@parFactNr", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iFactNr);
            parameters[9] = new SqlParameter("@parFactNr", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iFactNr);
            parameters[10] = new SqlParameter("@parTel", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sTel);
            parameters[11] = new SqlParameter("@parFax", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFax);
            parameters[12] = new SqlParameter("@parEmail", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sEmail);
            parameters[13] = new SqlParameter("@parWeb", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sWeb);
            parameters[14] = new SqlParameter("@parAdresa", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sAdresa);
            parameters[15] = new SqlParameter("@parCS", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dCS);
            parameters[16] = new SqlParameter("@parTVA", SqlDbType.Char, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, chTva);
            
        
            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[UPDATEFIRMA]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {
                
            }
            return toReturn;
        }

        public static int UPDATEFURNIZORI(
          System.String sRegCom,
          System.String sDenum,
          System.String sAdresa,
          System.String sCod,
          System.String sIban,
          System.String sBanca,
          System.String sEmail,
          System.String sCif)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[8];

            parameters[0] = new SqlParameter("@parRegCom", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sRegCom);
            parameters[1] = new SqlParameter("@parDenumire", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sDenum);
            parameters[2] = new SqlParameter("@parAdresa", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sAdresa);
            parameters[3] = new SqlParameter("@parCod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sCod);
            parameters[4] = new SqlParameter("@parIban", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sIban);
            parameters[5] = new SqlParameter("@parBanca", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sBanca);
            parameters[6] = new SqlParameter("@parEmail", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sEmail);
            parameters[7] = new SqlParameter("@parCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sCif);
           
            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[UPDATEFURNIZORI]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int INSERTFURNIZORI(
           System.String sFurnCif,
           System.String sFurnRegc,
           System.String sFurnDenum,
           System.String sFurnAdresa,
           System.String sFurnCod,
           System.String sFurnIban,
           System.String sFurnBanca,
           System.String sFurnEmail,
           System.DateTime dFurnData )
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[9];

            parameters[0] = new SqlParameter("@parFurnCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFurnCif);
            parameters[1] = new SqlParameter("@parFurnRegc", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFurnRegc);
            parameters[2] = new SqlParameter("@parFurnDenum", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFurnDenum);
            parameters[3] = new SqlParameter("@parFurnAdresa", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFurnAdresa);
            parameters[4] = new SqlParameter("@parFurnCod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFurnCod);
            parameters[5] = new SqlParameter("@parFurnIban", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFurnIban);
            parameters[6] = new SqlParameter("@parFurnBanca", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFurnBanca);
            parameters[7] = new SqlParameter("@parFurnEmail", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFurnEmail);
            parameters[8] = new SqlParameter("@parFurnData", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dFurnData);

            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[INSERTFURNIZORI]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int UPDATEPRODUSE(
        System.Int32 iId,
        System.String sDenum,
        System.String sCod,
        System.String sUM,
        System.Int32 iTva)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[5];

            parameters[0] = new SqlParameter("@parId", SqlDbType.Int, 18, ParameterDirection.Input, true, 18, 0, "", DataRowVersion.Current, iId);
            parameters[1] = new SqlParameter("@parDenumire", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sDenum);
            parameters[2] = new SqlParameter("@parCod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sCod);
            parameters[3] = new SqlParameter("@parUM", SqlDbType.VarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sUM);
            parameters[4] = new SqlParameter("@parTva", SqlDbType.Int, 4, ParameterDirection.Input, true, 4, 0, "", DataRowVersion.Current, iTva);
            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[UPDATEPRODUSE]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int UPDATESTOCURI(
        System.Int32 iId,
        System.Int32 iCant,
        System.Double iPretV,
        System.Int32 iType)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[4];

            parameters[0] = new SqlParameter("@parId", SqlDbType.Int, 18, ParameterDirection.Input, true, 18, 0, "", DataRowVersion.Current, iId);
            parameters[1] = new SqlParameter("@parCant", SqlDbType.Int, 18, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, iCant );
            parameters[2] = new SqlParameter("@parPretV", SqlDbType.Float, 18, ParameterDirection.Input, true, 2, 0, "", DataRowVersion.Current, iPretV );
            parameters[3] = new SqlParameter("@iType", SqlDbType.Int, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, iType);
            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[UPDATESTOCURI]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int UPDATECLIENTI(
         System.String sRegCom,
         System.String sDenum,
         System.String sAdresa,
         System.String sCod,
         System.String sIban,
         System.String sBanca,
         System.String sEmail,
         System.String sCif)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[8];

            parameters[0] = new SqlParameter("@parRegCom", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sRegCom);
            parameters[1] = new SqlParameter("@parDenumire", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sDenum);
            parameters[2] = new SqlParameter("@parAdresa", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sAdresa);
            parameters[3] = new SqlParameter("@parCod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sCod);
            parameters[4] = new SqlParameter("@parIban", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sIban);
            parameters[5] = new SqlParameter("@parBanca", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sBanca);
            parameters[6] = new SqlParameter("@parEmail", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sEmail);
            parameters[7] = new SqlParameter("@parCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sCif);

            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[UPDATECLIENTI]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int INSERTCLIENTI(
           System.String sClCif,
           System.String sClRegc,
           System.String sClDenum,
           System.String sClAdresa,
           System.String sClCod,
           System.String sClIban,
           System.String sClBanca,
           System.String sClEmail,
           System.DateTime dClData)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[9];

            parameters[0] = new SqlParameter("@parClCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClCif);
            parameters[1] = new SqlParameter("@parClRegc", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClRegc);
            parameters[2] = new SqlParameter("@parClDenum", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClDenum);
            parameters[3] = new SqlParameter("@parClAdresa", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClAdresa);
            parameters[4] = new SqlParameter("@parClCod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClCod);
            parameters[5] = new SqlParameter("@parClIban", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClIban);
            parameters[6] = new SqlParameter("@parClBanca", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClBanca);
            parameters[7] = new SqlParameter("@parClEmail", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClEmail);
            parameters[8] = new SqlParameter("@parClData", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dClData);

            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[INSERTCLIENTI]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int INSERTPRODUSE(
          System.String sCod,
          System.String sUM,
          System.String sDenum,
          System.Int32 iTVA)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[4];

            parameters[0] = new SqlParameter("@parCod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sCod);
            parameters[1] = new SqlParameter("@parUm", SqlDbType.VarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sUM );
            parameters[2] = new SqlParameter("@parDenumire", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sDenum);
            parameters[3] = new SqlParameter("@parCotaTva", SqlDbType.Int, 4, ParameterDirection.Input, true, 4, 0, "", DataRowVersion.Current, iTVA);

            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[INSERTPRODUSE]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int INSERTSTOC(
         System.Int32 iProdId,
         System.Int32 iCant,
         System.Double dPretVz
         )
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[3];

            parameters[0] = new SqlParameter("@parProdId", SqlDbType.Int, 18, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, iProdId );
            parameters[1] = new SqlParameter("@parCant", SqlDbType.Int, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, iCant);
            parameters[2] = new SqlParameter("@parPretVz", SqlDbType.Float, 18, ParameterDirection.Input, true, 2, 0, "", DataRowVersion.Current, dPretVz);

            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[INSERTSTOC]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int INSERTRECEPTII(
           System.String sNirSerie,
           System.Int32 iNirNumar,
           System.DateTime dNirData,
           System.String sFzCif,
           System.String sAviz,
           System.DateTime dAvizData,
           System.String sNirDelegat,
           System.String sNirGestionar,
           System.String sNirMentiuni,
           System.Double dTotal,
           System.String sFirmaCif)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[11];

            parameters[0] = new SqlParameter("@parNirSerie", SqlDbType.VarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sNirSerie);
            parameters[1] = new SqlParameter("@parNirNr", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iNirNumar);
            parameters[2] = new SqlParameter("@parNirData", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dNirData);
            parameters[3] = new SqlParameter("@parFzCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFzCif);
            parameters[4] = new SqlParameter("@parAviz", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sAviz);
            parameters[5] = new SqlParameter("@parDataAviz", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dAvizData);
            parameters[6] = new SqlParameter("@parNirDelegat", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sNirDelegat);
            parameters[7] = new SqlParameter("@parNirGestionar", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sNirGestionar);
            parameters[8] = new SqlParameter("@parNirMentiuni", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sNirMentiuni);
            parameters[9] = new SqlParameter("@parNirTotal", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dTotal);
            parameters[10] = new SqlParameter("@parFirmaCif", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFirmaCif);
            


            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[INSERTRECEPTII]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int UPDATERECEPTII(
           System.Int32 iRecepId,
           System.String sNirSerie,
           System.Int32 iNirNumar,
           System.DateTime dNirData,
           System.String sFzCif,
           System.String sAviz,
           System.DateTime dAvizData,
           System.String sNirDelegat,
           System.String sNirGestionar,
           System.String sNirMentiuni,
           System.Double dTotal)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[11];

            parameters[0] = new SqlParameter("@parNirId", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iRecepId);
            parameters[1] = new SqlParameter("@parNirSerie", SqlDbType.VarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sNirSerie);
            parameters[2] = new SqlParameter("@parNirNr", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iNirNumar);
            parameters[3] = new SqlParameter("@parNirData", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dNirData);
            parameters[4] = new SqlParameter("@parFzCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFzCif);
            parameters[5] = new SqlParameter("@parAviz", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sAviz);
            parameters[6] = new SqlParameter("@parDataAviz", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dAvizData);
            parameters[7] = new SqlParameter("@parNirDelegat", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sNirDelegat);
            parameters[8] = new SqlParameter("@parNirGestionar", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sNirGestionar);
            parameters[9] = new SqlParameter("@parNirMentiuni", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sNirMentiuni);
            parameters[10] = new SqlParameter("@parNirTotal", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dTotal);


            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[UPDATERECEPTII]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static DataTable GETRECEPTII(string dataInceput, string dataSfarsit, string serie, string numar, string furnCif, string prodId)
        {
            System.Int32 returnValue = 0;

            return GETRECEPTII(
                dataInceput,
                dataSfarsit,
                serie,
                numar,
                furnCif,
                prodId, 
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETRECEPTII(
            string dataInceput,
            string dataSfarsit,
            string serie,
            string numar,
            string furnCif,
            string prodId,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[7];
            
            parameters[0] = new SqlParameter("@dataInceput", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dataInceput);
            parameters[1] = new SqlParameter("@dataSfarsit", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dataSfarsit);
            parameters[2] = new SqlParameter("@serie", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, serie);
            parameters[3] = new SqlParameter("@numar", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, numar);
            parameters[4] = new SqlParameter("@furnCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, furnCif );
            parameters[5] = new SqlParameter("@prodId", SqlDbType.VarChar, 18, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, prodId );
          
            parameters[6] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETRECEPTII");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETRECEPTII]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }

        public static DataTable GETTOPPRODUSE(string data, string luna, int iStoc0)
        {
            System.Int32 returnValue = 0;

            return GETTOPPRODUSE(
                data,
                luna,
                iStoc0,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETTOPPRODUSE(
            string data,
            string luna,
            int iStoc0,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[4];

            parameters[0] = new SqlParameter("@data", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, data);
            parameters[1] = new SqlParameter("@luna", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, luna);
            parameters[2] = new SqlParameter("@iStoc0", SqlDbType.Int, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, iStoc0 );
            parameters[3] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETTOPPRODUSE");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETTOPPRODUSE]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }

        public static DataTable GETFACTURI(string dataInceput, string dataSfarsit, string serie, string numar, string clCif, string prodId)
        {
            System.Int32 returnValue = 0;

            return GETFACTURI(
                dataInceput,
                dataSfarsit,
                serie,
                numar,
                clCif,
                prodId,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETFACTURI(
            string dataInceput,
            string dataSfarsit,
            string serie,
            string numar,
            string clCif,
            string prodId,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[7];

            parameters[0] = new SqlParameter("@dataInceput", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dataInceput);
            parameters[1] = new SqlParameter("@dataSfarsit", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dataSfarsit);
            parameters[2] = new SqlParameter("@serie", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, serie);
            parameters[3] = new SqlParameter("@numar", SqlDbType.VarChar, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, numar);
            parameters[4] = new SqlParameter("@clCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, clCif );
            parameters[5] = new SqlParameter("@prodId", SqlDbType.VarChar, 18, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, prodId);
           
            parameters[6] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETFACTURI");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETFACTURI]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }

        public static DataTable GETFURNIZORI(string denumire, string cif, string cod)
        {
            System.Int32 returnValue = 0;

            return GETFURNIZORI(
                denumire,
                cif,
                cod,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETFURNIZORI(
            string denumire,
            string cif,
            string cod,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[4];

            parameters[0] = new SqlParameter("@denumire", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, denumire);
            parameters[1] = new SqlParameter("@cif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cif);
            parameters[2] = new SqlParameter("@cod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cod);
            parameters[3] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETFURNIZORI");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETFURNIZORI]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }
        public static DataTable GETSTOCURI(string denumire, string cod, string um, string cota, string mic, string mare)
        {
            System.Int32 returnValue = 0;

            return GETSTOCURI(
                denumire,
                cod,
                um, 
                cota,
                mic,
                mare,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETSTOCURI(
            string denumire,
            string cod,
            string um,
            string cota,
            string mic,
            string mare,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[7];

            parameters[0] = new SqlParameter("@denumire", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, denumire);
            parameters[1] = new SqlParameter("@cod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cod);
            parameters[2] = new SqlParameter("@um", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, um);
            parameters[3] = new SqlParameter("@cota", SqlDbType.VarChar, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cota);
            parameters[4] = new SqlParameter("@mic", SqlDbType.VarChar, 18, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, mic);
            parameters[5] = new SqlParameter("@mare", SqlDbType.VarChar, 18, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, mare);
           
            parameters[6] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETSTOCURI");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETSTOCURI]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }

        public static DataTable GETCLIENTI(string denumire, string cif, string cod)
        {
            System.Int32 returnValue = 0;

            return GETCLIENTI(
                denumire,
                cif,
                cod,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETCLIENTI(
            string denumire,
            string cif,
            string cod,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[4];

            parameters[0] = new SqlParameter("@denumire", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, denumire);
            parameters[1] = new SqlParameter("@cif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cif);
            parameters[2] = new SqlParameter("@cod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cod);
            parameters[3] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETCLIENTI");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETCLIENTI]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }

        public static DataTable GETPRODUSE(string denumire, string cod, string um, string cota)
        {
            System.Int32 returnValue = 0;

            return GETPRODUSE(
                denumire,
                cod,
                um, 
                cota,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETPRODUSE(
            string denumire,
            string cod,
            string um,
            string cota,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[5];

            parameters[0] = new SqlParameter("@denumire", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, denumire);
            parameters[1] = new SqlParameter("@cod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cod);
            parameters[2] = new SqlParameter("@um", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, um);
            parameters[3] = new SqlParameter("@cota", SqlDbType.VarChar, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cota);
           
            parameters[4] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETPRODUSE");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETPRODUSE]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }

        public static DataTable GETSTOCSITUATIE(string data, string luna)
        {
            System.Int32 returnValue = 0;

            return GETSTOCSITUATIE(
                data,
                luna,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETSTOCSITUATIE(
            string data,
            string luna,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[3];

            parameters[0] = new SqlParameter("@data", SqlDbType.VarChar, 15, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, data);
            parameters[1] = new SqlParameter("@luna", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, luna);
            parameters[2] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETSTOCSITUATIE");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETSTOCSITUATIE]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }

        public static DataTable GETPRODUSESTOC(string denumire, string cod, short bCant)
        {
            System.Int32 returnValue = 0;

            return GETPRODUSESTOC(
                denumire,
                cod,
                bCant,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETPRODUSESTOC(
            string denumire,
            string cod,
            short bCant,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[4];

            parameters[0] = new SqlParameter("@denumire", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, denumire);
            parameters[1] = new SqlParameter("@cod", SqlDbType.VarChar, 20, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, cod);
            parameters[2] = new SqlParameter("@bCant", SqlDbType.Bit, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, bCant);
            parameters[3] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETPRODUSESTOC");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETPRODUSESTOC]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }


        public static DataTable GETPRODRECEP(int recepId)
        {
            System.Int32 returnValue = 0;

            return GETPRODRECEP(
                recepId,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETPRODRECEP(
           System.Int32 recepId,
           ref System.Int32 returnValue,
           SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[2];

            parameters[0] = new SqlParameter("@recepId", SqlDbType.Int , 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, recepId);
            parameters[1] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETPRODRECEP");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETPRODRECEP]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }

        public static SqlDataAdapter  ReportGETRECEPTII(int recepId)
        {
            System.Int32 returnValue = 0;

            return ReportGETRECEPTII(
                recepId,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static SqlDataAdapter ReportGETRECEPTII(
            int recepId,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[2];

            parameters[0] = new SqlParameter("@recepId", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, recepId);
            parameters[1] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            SqlDataAdapter daResult = new SqlDataAdapter ();
            bool hasSucceeded = CallRetrievalStoredProcedureReport("[dbStockMentor].[dbo].[ReportGETRECEPTII]", parameters, daResult);

            return daResult;
        }

        //facturi
        public static int INSERTFACTURI(
   System.String sFactSerie,
   System.Int32 iFactNumar,
   System.DateTime dFactData,
   System.String sClCif,
   System.String sFactDelegat,
   System.String sFactIntocmit,
   System.String sFactMentiuni,
   System.Double dValTva,
   System.Double dTotalFaraTva,
   System.Double dTotalGeneral,
   System.String sFirmaCif
     )
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[11];

            parameters[0] = new SqlParameter("@parFactSerie", SqlDbType.VarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactSerie);
            parameters[1] = new SqlParameter("@parFactNr", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iFactNumar);
            parameters[2] = new SqlParameter("@parFactData", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dFactData);
            parameters[3] = new SqlParameter("@parClCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClCif);
            parameters[4] = new SqlParameter("@parFactDelegat", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactDelegat);
            parameters[5] = new SqlParameter("@parFactIntocmit", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactIntocmit);
            parameters[6] = new SqlParameter("@parFactMentiuni", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactMentiuni);
            parameters[7] = new SqlParameter("@parFactValTva", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dValTva);
            parameters[8] = new SqlParameter("@parFactTotalFaraTVA", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dTotalFaraTva);
            parameters[9] = new SqlParameter("@parFactTotalGeneral", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dTotalGeneral);
            parameters[10] = new SqlParameter("@parFirmaCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFirmaCif);


            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[INSERTFACTURI]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static int UPDATEFACTURI(
           System.Int32 iFactId,
           System.String sFactSerie,
           System.Int32 iFactNumar,
           System.DateTime dFactData,
           System.String sClCif,
           System.String sFactDelegat,
           System.String sFactIntocmit,
           System.String sFactMentiuni,
           System.Double dValTva,
           System.Double dTotalFaraTva,
           System.Double dTotalGeneral)
        {
            // create parameters
            SqlParameter[] parameters = new SqlParameter[11];

            parameters[0] = new SqlParameter("@parFactId", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iFactId);
            parameters[1] = new SqlParameter("@parFactSerie", SqlDbType.VarChar, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactSerie);
            parameters[2] = new SqlParameter("@parFactNr", SqlDbType.Int, 10, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, iFactNumar);
            parameters[3] = new SqlParameter("@parFactData", SqlDbType.DateTime, 25, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dFactData);
            parameters[4] = new SqlParameter("@parClCif", SqlDbType.VarChar, 50, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sClCif);
            parameters[5] = new SqlParameter("@parFactDelegat", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactDelegat);
            parameters[6] = new SqlParameter("@parFactIntocmit", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactIntocmit);
            parameters[7] = new SqlParameter("@parFactMentiuni", SqlDbType.VarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, sFactMentiuni);
            parameters[8] = new SqlParameter("@parFactValTva", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dValTva);
            parameters[9] = new SqlParameter("@parFactTotalFaraTVA", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dTotalFaraTva);
            parameters[10] = new SqlParameter("@parFactTotalGeneral", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, dTotalGeneral);



            // Call the stored proc.
            int toReturn = 0;
            try
            {
                toReturn = CallStoredProcedure("[dbStockMentor].[dbo].[UPDATEFACTURI]", parameters);
            }
            catch
            {
                throw;
            }
            finally
            {

            }
            return toReturn;
        }

        public static SqlDataAdapter ReportGETFACTURI(int recepId)
        {
            System.Int32 returnValue = 0;

            return ReportGETFACTURI(
                recepId,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static SqlDataAdapter ReportGETFACTURI(
            int factId,
            ref System.Int32 returnValue,
            SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[2];

            parameters[0] = new SqlParameter("@factId", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, factId);
            parameters[1] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            SqlDataAdapter daResult = new SqlDataAdapter();
            bool hasSucceeded = CallRetrievalStoredProcedureReport("[dbStockMentor].[dbo].[ReportGETFACTURI]", parameters, daResult);

            return daResult;
        }

        public static DataTable GETPRODFACT(int factId)
        {
            System.Int32 returnValue = 0;

            return GETPRODFACT(
                factId,
                ref returnValue,
                new SqlDataAdapter());
        }

        public static DataTable GETPRODFACT(
           System.Int32 factId,
           ref System.Int32 returnValue,
           SqlDataAdapter adapter)
        {

            // create parameters
            SqlParameter[] parameters = new SqlParameter[2];

            parameters[0] = new SqlParameter("@factId", SqlDbType.Int, 10, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, factId);
            parameters[1] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);

            // Call the stored proc.
            DataSet dsResult = new DataSet("GETPRODFACT");
            bool hasSucceeded = CallRetrievalStoredProcedure("[dbStockMentor].[dbo].[GETPRODFACT]", parameters, dsResult);

            DataTable toReturn = dsResult.Tables[0];
            dsResult.Tables.Remove(toReturn);
            return toReturn;
        }


        //end facturi
        private static bool CallRetrievalStoredProcedure(string procName, SqlParameter[] parameters, DataSet dataSetToFill)
        {
            SqlCommand command = new SqlCommand(procName, conn);
            
            command.CommandType = CommandType.StoredProcedure;


            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = command;

            for (int i = 0; i < parameters.Length; i++)
            {
                command.Parameters.Add(parameters[i]);
            }
            adapter.Fill(dataSetToFill);

            return true;
        }

        private static bool CallRetrievalStoredProcedureReport(string procName, SqlParameter[] parameters, SqlDataAdapter adapter)
        {
            SqlCommand command = new SqlCommand(procName, conn);

            command.CommandType = CommandType.StoredProcedure;


            adapter.SelectCommand = command;

            for (int i = 0; i < parameters.Length; i++)
            {
                command.Parameters.Add(parameters[i]);
            }
            

            return true;
        }

        private static int CallStoredProcedure(String procName, SqlParameter[] parameters)
        {
            SqlCommand command = new SqlCommand(procName,conn);
           
            command.CommandType = CommandType.StoredProcedure;
            

            int toReturn = -1;
            try
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    command.Parameters.Add(parameters[i]);
                }

                
                toReturn = command.ExecuteNonQuery();
            }
            finally
            {
               
            }
            return toReturn;
        }
    }
}
